<?php $this->load->view('inc/header.php');?>
<?php $this->load->view('cat/inc_sm.php');?>
<div class="col-right">
	<?php if(!empty($mid)):?>
	<div class="opt">
		<a class="wm-ajax" 
			wmtitle="添加分类"
			wmw="500"
			wmh="460"
			href="<?php echo site_url('c=cat&m=ajax_add');?>">添加分类</a>
		<span>&nbsp;|&nbsp;</span>
		<a id="cat-handle-fold" href="javascript:void(0);">全部收起</a>
		<span>&nbsp;|&nbsp;</span>
		<a id="cat-handle-open" href="javascript:void(0);">全部展开</a>
	</div>
	<?php endif;?>

	<div class="box">
		<div class="box-t">
			<span class="fl">添加列表</span>	
			<span class="fr">
				<?php html_select($opt_model,fd('mid'),'id="slt-model"','--选择模型--');?>
			</span>
		</div>
		<div class="box-c" id="cat-tree">
			<?php if(!empty($mid)):?>
			<?php foreach ($tree_cat as $k => $v):?>
				<div class="cat-item">
					<div class="ci-t">
						<?php if($v['has_sub']):?>
							<a class="handle-fold" href="#">－</a>
						<?php endif;?>

						<?php echo $v['title']?>
					</div>
					<div class="ci-o">
						<a class="wm-ajax" 
							wmtitle="添加子分类"
							wmw="500"
							wmh="300"
							href="<?php echo site_url('c=cat&m=ajax_add&pid='.$v['id']);?>">添加子分类</a>
						&nbsp;
						<a class="wm-ajax" 
							wmtitle="编辑分类"
							wmw="500"
							wmh="300"
							href="<?php echo site_url('c=cat&m=ajax_edit&id='.$v['id']);?>">编辑</a>
						&nbsp;
						<a class="btn-ajax-confirm" msg="确定要删除吗？" 
							href="<?php echo site_url('c=cat&m=del_do&id='.$v['id']);?>">删除</a>
					</div>
				</div>

				<?php
					if($v['has_sub'] == 1){
						echo '<div class="sub-wrp">';
					}else{
						if($k==(count($tree_cat)-1)) {
							for ($i=0;$i<$v['step'];$i++) {
								echo '</div>';
							}
						}else{
							for ($i=0;$i<($v['step']-$tree_cat[$k+1]['step']);$i++) {
								echo '</div>';
							}
						}
					}
				?>

			<?php endforeach;?>
			<?php else:?>
				<div>请选择模型先！</div>
			<?php endif;?>
		</div>
	</div>

</div>

<?php $this->load->view('inc/footer.php');?>

<script type="text/javascript">$(function(){

	$('#cat-tree .cat-item').hover(function(){
		$(this).addClass('b1');
	},function(){
		$(this).removeClass('b1');
	});

	$('#cat-tree .handle-fold').toggle(function(){
		$(this).parents('.cat-item').next().hide();
		$(this).html('').html('＋');
	},function(){
		$(this).parents('.cat-item').next().show();
		$(this).html('').html('－');
	});

	$('#cat-handle-fold').click(function(){
		$('#cat-tree .sub-wrp').hide();
		$('#cat-tree .handle-fold').html('').html('＋');
	});

	$('#cat-handle-open').click(function(){
		$('#cat-tree .sub-wrp').show();
		$('#cat-tree .handle-fold').html('').html('－');
	});

	$('#slt-model').change(function(){
		var mid = $(this).val();
		var url = '<?php echo site_url("c=model&m=set_mid&mid=");?>'+mid;
		$.ajax({
			type: 'get',
			url: url,
			async: false,
			dataType:'json',
			success:function(msg){
	    		ajax_back(msg);
			}
		});		
	});

});</script>
